package com.msh.platform.elm.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import com.msh.platform.elm.common.constants.Constants;

public class DateUtils {

	/**
	* 根据日期获取对应的星期几
	*/
	public static String getWeekByDate(String date) {
		String dayOfweek = "-1";
		try {
			Date myDate = Constants.myFormatter.parse(date);
			SimpleDateFormat formatter = new SimpleDateFormat("E");
			String str = formatter.format(myDate);
			dayOfweek = str;
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dayOfweek;
	}
	
	/**
	* 根据日期获取对应的星期几数字
	*/
	public static int getIntWeekByDate(String date) {
		String week = getWeekByDate(date);
		switch(week){
	        case "星期一":
	            return 1;
	        case "星期二":
	        	return 2;
	        case "星期三":
	        	return 3;
	        case "星期四":
	        	return 4;
	        case "星期五":
	        	return 5;
	        case "星期六":
	        	return 6;
	        default:
	        	return 7;
        }
	}
	
	/**
	* 根据日期字符串获取对应的几号数字
	*/
	public static int getDayByDate(String date) {
		int day = 0;
		if(!"".equals(date)) {
			String dayStr = date.substring(8, 10);
			day = Integer.parseInt(dayStr);
		}
		return day;
	}
	
	public static void main(String[] args) {
		int week = getIntWeekByDate("2018-12-18");
		System.out.println(week);
	}

}
